<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.1.1">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/avatar.jpg">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/avatar.jpg">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/avatar.jpg">
  <link rel="mask-icon" href="/images/avatar.jpg" color="#222">
  <meta name="msvalidate.01" content="4AF2328B2035748153A041B7EEF3D15C">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Noto+Serif+SC:300,300italic,400,400italic,700,700italic%7CLobster:300,300italic,400,400italic,700,700italic%7CPingFang+SC:300,300italic,400,400italic,700,700italic%7CRoboto+Mono:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.33/fancybox/fancybox.css" integrity="sha256-gkQVf8UKZgQ0HyuxL/VnacadJ+D2Kox2TCEBuNQg5+w=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"ethanliu6.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":true,"sidebar":{"position":"left","display":"always","padding":12,"offset":18},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":true,"color":"#222","save":"manual"},"mediumzoom":true,"lazyload":true,"pangu":false,"comments":{"style":"buttons","active":"changyan","storage":true,"lazyload":false,"nav":null,"activeClass":"changyan"},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":6,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="JavaSE进阶——Day07 该篇主要讲解Java中的集合嵌套、Collections工具类、日志框架">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaSE进阶——Day07 集合嵌套、Collections工具类、日志框架">
<meta property="og:url" content="http://ethanliu6.github.io/2024/04/22/JavaNotes/JavaSE%E8%BF%9B%E9%98%B6/day07/2024-04-19-JavaSE%E8%BF%9B%E9%98%B6%E2%80%94%E2%80%94Day06-%E6%8E%92%E5%BA%8F%E6%9F%A5%E6%89%BE%E7%AE%97%E6%B3%95%E3%80%81Map%E9%9B%86%E5%90%88%E3%80%81%E9%9B%86%E5%90%88%E5%B5%8C%E5%A5%97%E3%80%81%E6%96%97%E5%9C%B0%E4%B8%BB%E6%A1%88%E4%BE%8B/index.html">
<meta property="og:site_name" content="&lt;font color&#x3D;&#39;white&#39; &gt;Ethan の Blog&lt;&#x2F;font&gt;">
<meta property="og:description" content="JavaSE进阶——Day07 该篇主要讲解Java中的集合嵌套、Collections工具类、日志框架">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/EthanLiu6/ImgsForMe/blog_images/image-20240423230805585.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/EthanLiu6/ImgsForMe/blog_images/image-20240423221400608.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/EthanLiu6/ImgsForMe/blog_images/image-20240424002912733.png">
<meta property="article:published_time" content="2024-04-22T15:00:00.000Z">
<meta property="article:modified_time" content="2024-04-24T15:50:28.717Z">
<meta property="article:author" content="Ethan Liu">
<meta property="article:tag" content="Java">
<meta property="article:tag" content="Java进阶">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/EthanLiu6/ImgsForMe/blog_images/image-20240423230805585.png">


<link rel="canonical" href="http://ethanliu6.github.io/2024/04/22/JavaNotes/JavaSE%E8%BF%9B%E9%98%B6/day07/2024-04-19-JavaSE%E8%BF%9B%E9%98%B6%E2%80%94%E2%80%94Day06-%E6%8E%92%E5%BA%8F%E6%9F%A5%E6%89%BE%E7%AE%97%E6%B3%95%E3%80%81Map%E9%9B%86%E5%90%88%E3%80%81%E9%9B%86%E5%90%88%E5%B5%8C%E5%A5%97%E3%80%81%E6%96%97%E5%9C%B0%E4%B8%BB%E6%A1%88%E4%BE%8B/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://ethanliu6.github.io/2024/04/22/JavaNotes/JavaSE%E8%BF%9B%E9%98%B6/day07/2024-04-19-JavaSE%E8%BF%9B%E9%98%B6%E2%80%94%E2%80%94Day06-%E6%8E%92%E5%BA%8F%E6%9F%A5%E6%89%BE%E7%AE%97%E6%B3%95%E3%80%81Map%E9%9B%86%E5%90%88%E3%80%81%E9%9B%86%E5%90%88%E5%B5%8C%E5%A5%97%E3%80%81%E6%96%97%E5%9C%B0%E4%B8%BB%E6%A1%88%E4%BE%8B/","path":"2024/04/22/JavaNotes/JavaSE进阶/day07/2024-04-19-JavaSE进阶——Day06-排序查找算法、Map集合、集合嵌套、斗地主案例/","title":"JavaSE进阶——Day07 集合嵌套、Collections工具类、日志框架"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>JavaSE进阶——Day07 集合嵌套、Collections工具类、日志框架 | <font color='white' >Ethan の Blog</font></title>
  








  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<style>.darkmode--activated{--body-bg-color:#282828;--content-bg-color:#333;--card-bg-color:#555;--text-color:#ccc;--blockquote-color:#bbb;--link-color:#ccc;--link-hover-color:#eee;--brand-color:#ddd;--brand-hover-color:#ddd;--table-row-odd-bg-color:#282828;--table-row-hover-bg-color:#363636;--menu-item-bg-color:#555;--btn-default-bg:#222;--btn-default-color:#ccc;--btn-default-border-color:#555;--btn-default-hover-bg:#666;--btn-default-hover-color:#ccc;--btn-default-hover-border-color:#666;--highlight-background:#282b2e;--highlight-foreground:#a9b7c6;--highlight-gutter-background:#34393d;--highlight-gutter-foreground:#9ca9b6}.darkmode--activated img{opacity:.75}.darkmode--activated img:hover{opacity:.9}.darkmode--activated code{color:#69dbdc;background:0 0}button.darkmode-toggle{z-index:9999}.darkmode-ignore,img{display:flex!important}.beian img{display:inline-block!important}</style></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title"><font color='white' >Ethan の Blog</font></p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description"><font color='#FDABC1' size=3>清醒的停留，胜过——盲目的前行</font></p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-关于我"><a href="/aboutme/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">18</span></a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">14</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">53</span></a></li><li class="menu-item menu-item-love"><a href="/categories/Love/" rel="section"><i class="fas fa-heart fa-fw"></i>Love</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#map%E9%9B%86%E5%90%88%E5%8F%8C%E5%88%97%E9%9B%86%E5%90%88"><span class="nav-number">1.</span> <span class="nav-text">Map集合：(双列集合)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%9B%9E%E9%A1%BE"><span class="nav-number">1.1.</span> <span class="nav-text">回顾</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%A1%88%E4%BE%8B"><span class="nav-number">1.2.</span> <span class="nav-text">案例</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%9B%86%E5%90%88%E7%9A%84%E5%B5%8C%E5%A5%97"><span class="nav-number">2.</span> <span class="nav-text">集合的嵌套</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#list%E5%B5%8C%E5%A5%97list"><span class="nav-number">2.1.</span> <span class="nav-text">List嵌套List</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#list%E5%B5%8C%E5%A5%97map"><span class="nav-number">2.2.</span> <span class="nav-text">List嵌套Map</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#map%E5%B5%8C%E5%A5%97map"><span class="nav-number">2.3.</span> <span class="nav-text">Map嵌套Map</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B5%8C%E5%A5%97%E9%9B%86%E5%90%88%E6%A2%B3%E7%90%86"><span class="nav-number">2.4.</span> <span class="nav-text">嵌套集合梳理</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#collections%E5%B7%A5%E5%85%B7%E7%B1%BB"><span class="nav-number">3.</span> <span class="nav-text">Collections工具类</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B7%A5%E5%85%B7%E7%B1%BB"><span class="nav-number">3.1.</span> <span class="nav-text">工具类</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#collections%E5%B7%A5%E5%85%B7%E7%B1%BB-1"><span class="nav-number">3.2.</span> <span class="nav-text">Collections工具类</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%96%97%E5%9C%B0%E4%B8%BB%E6%A1%88%E4%BE%8B"><span class="nav-number">4.</span> <span class="nav-text">斗地主案例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%9C%80%E6%B1%82"><span class="nav-number">4.1.</span> <span class="nav-text">需求</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%80%BB%E8%BE%91%E4%BB%A3%E7%A0%81"><span class="nav-number">4.2.</span> <span class="nav-text">逻辑代码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%81%87%E5%88%B0%E9%97%AE%E9%A2%98"><span class="nav-number">4.3.</span> <span class="nav-text">遇到问题</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%97%A5%E5%BF%97%E6%A1%86%E6%9E%B6"><span class="nav-number">5.</span> <span class="nav-text">日志框架</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%97%A5%E5%BF%97%E6%8A%80%E6%9C%AF%E7%9A%84%E6%A6%82%E8%BF%B0"><span class="nav-number">5.1.</span> <span class="nav-text">日志技术的概述</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%97%A5%E5%BF%97%E6%8A%80%E6%9C%AF%E4%BD%93%E7%B3%BB%E7%BB%93%E6%9E%84"><span class="nav-number">5.2.</span> <span class="nav-text">日志技术体系结构</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#logback%E6%A6%82%E8%BF%B0"><span class="nav-number">5.3.</span> <span class="nav-text">Logback概述</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#logback%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8"><span class="nav-number">5.4.</span> <span class="nav-text">Logback快速入门</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%A1%A5%E5%85%85"><span class="nav-number">5.4.1.</span> <span class="nav-text">补充</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8logback%E7%9A%84%E6%AD%A5%E9%AA%A4"><span class="nav-number">5.4.2.</span> <span class="nav-text">使用Logback的步骤：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#logback%E6%97%A5%E5%BF%97%E6%A1%86%E6%9E%B6%E7%9A%84%E6%A0%B8%E5%BF%83logback.xml"><span class="nav-number">5.4.3.</span> <span class="nav-text">Logback日志框架的核心：logback.xml</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#logback%E6%97%A5%E5%BF%97%E7%BA%A7%E5%88%AB%E4%BB%8E%E5%A4%A7%E5%88%B0%E5%B0%8F"><span class="nav-number">5.4.4.</span> <span class="nav-text">Logback日志级别（从大到小）：</span></a></li></ol></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Ethan Liu"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Ethan Liu</p>
  <div class="site-description" itemprop="description"><font color='#0000FF' size=1.5px>语言学 | NLP | Py | Java</font></div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">53</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">18</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2V0aGFubGl1Ng==" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;ethanliu6"><i class="fab fa-github fa-fw"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="bWFpbHRvOmxpdWUyMzM2QGdtYWlsLmNvbQ==" title="E-Mail → mailto:liue2336@gmail.com"><i class="fa fa-envelope fa-fw"></i>E-Mail</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9zcGFjZS5iaWxpYmlsaS5jb20vMTMyNzA5OTk3Nw==" title="BiliBili → https:&#x2F;&#x2F;space.bilibili.com&#x2F;1327099977"><i class="fa-brands fa-bilibili fa-fw"></i>BiliBili</span>
      </span>
      <span class="links-of-author-item">
        <a href="/categories/Love/" title="Love → &#x2F;categories&#x2F;Love&#x2F;" rel="noopener me"><i class="fa fa-heart fa-fw"></i>Love</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://ethanliu6.github.io/2024/04/22/JavaNotes/JavaSE%E8%BF%9B%E9%98%B6/day07/2024-04-19-JavaSE%E8%BF%9B%E9%98%B6%E2%80%94%E2%80%94Day06-%E6%8E%92%E5%BA%8F%E6%9F%A5%E6%89%BE%E7%AE%97%E6%B3%95%E3%80%81Map%E9%9B%86%E5%90%88%E3%80%81%E9%9B%86%E5%90%88%E5%B5%8C%E5%A5%97%E3%80%81%E6%96%97%E5%9C%B0%E4%B8%BB%E6%A1%88%E4%BE%8B/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Ethan Liu">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="<font color='white' >Ethan の Blog</font>">
      <meta itemprop="description" content="<font color='#0000FF' size=1.5px>语言学 | NLP | Py | Java</font>">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="JavaSE进阶——Day07 集合嵌套、Collections工具类、日志框架 | <font color='white' >Ethan の Blog</font>">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          JavaSE进阶——Day07 集合嵌套、Collections工具类、日志框架<span class="exturl post-edit-link" data-url="aHR0cHM6Ly9naXRodWIuY29tL0V0aGFuTGl1Ni9ldGhhbmxpdTYuZ2l0aHViLmlvL3RyZWUvbWFzdGVyL19wb3N0cy9KYXZhTm90ZXMvSmF2YVNF6L+b6Zi2L2RheTA3LzIwMjQtMDQtMTktSmF2YVNF6L+b6Zi24oCU4oCURGF5MDYt5o6S5bqP5p+l5om+566X5rOV44CBTWFw6ZuG5ZCI44CB6ZuG5ZCI5bWM5aWX44CB5paX5Zyw5Li75qGI5L6LLm1k" title="编辑"><i class="fa fa-pen-nib"></i></span>
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2024-04-22 23:00:00" itemprop="dateCreated datePublished" datetime="2024-04-22T23:00:00+08:00">2024-04-22</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2024-04-24 23:50:28" itemprop="dateModified" datetime="2024-04-24T23:50:28+08:00">2024-04-24</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Java%E5%85%A8%E6%A0%88/" itemprop="url" rel="index"><span itemprop="name">Java全栈</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Changyan：</span>
    
    <a title="JavaSE进阶——Day07 集合嵌套、Collections工具类、日志框架" href="/2024/04/22/JavaNotes/JavaSE%E8%BF%9B%E9%98%B6/day07/2024-04-19-JavaSE%E8%BF%9B%E9%98%B6%E2%80%94%E2%80%94Day06-%E6%8E%92%E5%BA%8F%E6%9F%A5%E6%89%BE%E7%AE%97%E6%B3%95%E3%80%81Map%E9%9B%86%E5%90%88%E3%80%81%E9%9B%86%E5%90%88%E5%B5%8C%E5%A5%97%E3%80%81%E6%96%97%E5%9C%B0%E4%B8%BB%E6%A1%88%E4%BE%8B/#SOHUCS" itemprop="discussionUrl">
      <span id="sourceId::37a2fead96ff8c04b3a8e68e23131f04" class="cy_cmt_count" itemprop="commentCount"></span>
    </a>
  </span>
  
  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>1.5k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>5 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><blockquote class="blockquote-center">
<p>JavaSE进阶——Day07
该篇主要讲解Java中的<strong>集合嵌套、Collections工具类、日志框架</strong></p>

</blockquote>
<span id="more"></span>
<h2 id="map集合双列集合">Map集合：(双列集合)</h2>
<h3 id="回顾">回顾</h3>
<div class="note primary"><ul>
<li>一次存储两个元素（key、value）
<ul>
<li>key不能重复、value可以重复</li>
<li>一个key只能对应一个value</li>
</ul></li>
<li>不能直接遍历（间接性遍历）
<ul>
<li>键找值：先获取Map集合中所有的key元素，遍历所有的key元素，在遍历过程中通过key找到value</li>
<li>键值对：先获取Map集合中所有的键值对对象(Map.Entry)，遍历所有的键值对对象，在遍历过程中获取到key和value</li>
</ul></li>
</ul>
</div>
<h3 id="案例">案例</h3>
<div class="note primary"><p>使用Map集合统计字符串中每个字符出现的次数</p>
</div>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> map.example;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.HashMap;</span><br><span class="line"><span class="keyword">import</span> java.util.Map;</span><br><span class="line"><span class="keyword">import</span> java.util.Set;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Author</span> EthanLiu 16693226842@163.com</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Date</span> 2024/4/22 21:58</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Project</span> JavaCode_SE_Advance</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Theme</span> 使用Map集合统计字符串中每个字符出现的次数</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MapDemo1</span> &#123;</span><br><span class="line">    <span class="comment">//统计字符串中每个字符出现的次数</span></span><br><span class="line">    <span class="comment">//&quot;ethanliuloveqiu&quot;</span></span><br><span class="line">    <span class="comment">//a(1)  q(1)  t(1)  e(2)  u(2)  v(1)  h(1)  i(2)  l(2)  n(1)  o(1)</span></span><br><span class="line">    </span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        <span class="comment">//字符串</span></span><br><span class="line">        <span class="type">String</span> <span class="variable">strs</span> <span class="operator">=</span> <span class="string">&quot;ethanliuloveqiu&quot;</span>;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//统计字符次数</span></span><br><span class="line">        <span class="comment">//初始化哈希表对象</span></span><br><span class="line">        Map&lt;Character, Integer&gt; recordMap = <span class="keyword">new</span> <span class="title class_">HashMap</span>&lt;&gt;();</span><br><span class="line"></span><br><span class="line">        <span class="comment">//遍历字符串</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">0</span>; i &lt; strs.length(); i++) &#123;</span><br><span class="line">            <span class="comment">//取出对应字符</span></span><br><span class="line">            <span class="type">char</span> <span class="variable">strChar</span> <span class="operator">=</span> strs.charAt(i); <span class="comment">// String类的charAt()方法</span></span><br><span class="line"></span><br><span class="line">            <span class="comment">//判断字符串是否存在</span></span><br><span class="line">            <span class="keyword">if</span> (recordMap.containsKey(strChar)) &#123;</span><br><span class="line">                <span class="comment">//2.存在: 通过该字符的key找value, 对value + 1, 将结果重新写入对应的key和value (修改)</span></span><br><span class="line">                recordMap.put(strChar, recordMap.get(strChar) + <span class="number">1</span>);</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                <span class="comment">//1.不存在: 将该字符作为key, 并初始化对应的value为1</span></span><br><span class="line">                recordMap.put(strChar, <span class="number">1</span>);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//System.out.println(recordMap);</span></span><br><span class="line">        <span class="comment">//遍历Map集合设置输出格式 (Map遍历方式2)</span></span><br><span class="line">        Set&lt;Map.Entry&lt;Character, Integer&gt;&gt; entries = recordMap.entrySet(); <span class="comment">//定义键值对对象的Set集合对象</span></span><br><span class="line">        <span class="keyword">for</span> (Map.Entry&lt;Character, Integer&gt; entry : entries) &#123; <span class="comment">//增强for遍历键值对</span></span><br><span class="line">            <span class="type">char</span> <span class="variable">key</span> <span class="operator">=</span> entry.getKey(); <span class="comment">//单个键值对取键</span></span><br><span class="line">            <span class="type">int</span> <span class="variable">value</span> <span class="operator">=</span> entry.getValue(); <span class="comment">//单个键值对取值</span></span><br><span class="line">            System.out.print(key + <span class="string">&quot;(&quot;</span> + value + <span class="string">&quot;)  &quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="集合的嵌套">集合的嵌套</h2>
<h3 id="list嵌套list">List嵌套List</h3>
<div class="note primary"><ul>
<li><p>使用场景举例：一年级有多个班级，每个班级有多名学生。要求保存每个班级的学生姓名，保存一个年级所有的班级信息</p></li>
<li><p>思路：</p>
<ul>
<li><p>可以使用List集合保存一个班级的学生</p></li>
<li><p>可以使用List集合保存所有班级</p></li>
</ul></li>
<li><p>因此我们可以定义集合如下：</p>
<ul>
<li>班级：List<String>
<ul>
<li>举例 : List<String> 一班 = {迪丽热巴 , 古力娜扎 ,马尔扎哈 ,欧阳娜娜}
List<String> 二班 = {李小璐 , 白百何 , 马蓉} List<String> 三班 = {林丹
,文章, 陈赫}</String></String></String></li>
</ul></String></li>
<li>年级：List&lt;List<String>&gt;
<ul>
<li>举例 : List&lt;List<String>&gt; 年级 = {一班 , 二班 , 三班}</String></li>
</ul></String></li>
</ul></li>
</ul>
</div>
<p>代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> nesting;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Author</span> EthanLiu 16693226842@163.com</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Date</span> 2024/4/23 08:48</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Project</span> JavaCode_SE_Advance</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Theme</span> List嵌套List集合</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ListNestListDemo</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        <span class="comment">//班级1</span></span><br><span class="line">        List&lt;String&gt; classes1 = <span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;&gt;();</span><br><span class="line">        classes1.add(<span class="string">&quot;迪丽热巴&quot;</span>);</span><br><span class="line">        classes1.add(<span class="string">&quot;古力娜扎&quot;</span>);</span><br><span class="line">        classes1.add(<span class="string">&quot;马尔扎哈&quot;</span>);</span><br><span class="line">        classes1.add(<span class="string">&quot;欧阳娜娜&quot;</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//班级2</span></span><br><span class="line">        List&lt;String&gt; classes2 = <span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;&gt;();</span><br><span class="line">        classes2.add(<span class="string">&quot;李小璐&quot;</span>);</span><br><span class="line">        classes2.add(<span class="string">&quot;白百何&quot;</span>);</span><br><span class="line">        classes2.add(<span class="string">&quot;马蓉&quot;</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//班级3</span></span><br><span class="line">        List&lt;String&gt; classes3 = <span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;&gt;();</span><br><span class="line">        classes3.add(<span class="string">&quot;林丹&quot;</span>);</span><br><span class="line">        classes3.add(<span class="string">&quot;文章&quot;</span>);</span><br><span class="line">        classes3.add(<span class="string">&quot;陈赫&quot;</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//年级 （存储多个班级）</span></span><br><span class="line">        List&lt;List&lt;String&gt;&gt; grade = <span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;&gt;();</span><br><span class="line">        grade.add(classes1);</span><br><span class="line">        grade.add(classes2);</span><br><span class="line">        grade.add(classes3);</span><br><span class="line">        </span><br><span class="line">        <span class="comment">//遍历List嵌套集合</span></span><br><span class="line">        <span class="keyword">for</span> (List&lt;String&gt; classes : grade) &#123;</span><br><span class="line">            <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">0</span>; i &lt; classes.size(); i++) &#123;</span><br><span class="line">                System.out.println(classes.get(i));</span><br><span class="line">            &#125;</span><br><span class="line">            System.out.println(<span class="string">&quot;-----------------&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="list嵌套map">List嵌套Map</h3>
<div class="note primary"><p>/* List嵌套Map :</p>
<p>使用场景举例：一年级有多个班级，每个班级有多名学生。要求保存每个班级的学生姓名，姓名有与之对应的学号，保存一年级所有的班级信息。</p>
<p>思路： 1 可以使用Map集合保存一个班级的学生（键是学号，值是名字） 2
可以使用List集合保存所有班级</p>
<p>因此我们可以定义集合如下：</p>
<p>班级：Map&lt;String,String&gt; 键是学号，值是姓名 举例 :
Map&lt;String,String&gt; 一班 = {it001 = 迪丽热巴 , it002 = 古力娜扎
,it003 = 马尔扎哈 ,it004 = 欧阳娜娜} Map&lt;String,String&gt; 二班 =
{it001 = 李小璐 , it002 = 白百何 , it003 = 马蓉}
Map&lt;String,String&gt; 三班 = {it001 = 林丹 ,it002 = 文章, it003 =
陈赫}</p>
<p>年级：List&lt;Map&lt;String,String&gt;&gt;保存每个班级的信息 举例 :
List&lt;Map&lt;String,String&gt;&gt; 年级 = {一班 , 二班 , 三班}</p>
<p>*/</p>
</div>
<p>代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> nesting;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Author</span> EthanLiu 16693226842@163.com</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Date</span> 2024/4/23 08:59</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Project</span> JavaCode_SE_Advance</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Theme</span> List嵌套Map</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ListNestMapDemo</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        <span class="comment">//班级1</span></span><br><span class="line">        Map&lt;String, String&gt; clases1 = <span class="keyword">new</span> <span class="title class_">HashMap</span>&lt;&gt;();</span><br><span class="line">        clases1.put(<span class="string">&quot;it001&quot;</span>, <span class="string">&quot;迪丽热巴&quot;</span>);</span><br><span class="line">        clases1.put(<span class="string">&quot;it002&quot;</span>, <span class="string">&quot;古力娜扎&quot;</span>);</span><br><span class="line">        clases1.put(<span class="string">&quot;it003&quot;</span>, <span class="string">&quot;马尔扎哈&quot;</span>);</span><br><span class="line">        clases1.put(<span class="string">&quot;it004&quot;</span>, <span class="string">&quot;欧阳娜娜&quot;</span>);</span><br><span class="line">        <span class="comment">//班级2</span></span><br><span class="line">        Map&lt;String, String&gt; clases2 = <span class="keyword">new</span> <span class="title class_">HashMap</span>&lt;&gt;();</span><br><span class="line">        clases2.put(<span class="string">&quot;it001&quot;</span>, <span class="string">&quot;李小璐&quot;</span>);</span><br><span class="line">        clases2.put(<span class="string">&quot;it002&quot;</span>, <span class="string">&quot;白百何&quot;</span>);</span><br><span class="line">        clases2.put(<span class="string">&quot;it003&quot;</span>, <span class="string">&quot;马蓉&quot;</span>);</span><br><span class="line">        <span class="comment">//班级1</span></span><br><span class="line">        Map&lt;String, String&gt; clases3 = <span class="keyword">new</span> <span class="title class_">HashMap</span>&lt;&gt;();</span><br><span class="line">        clases3.put(<span class="string">&quot;it001&quot;</span>, <span class="string">&quot;林丹&quot;</span>);</span><br><span class="line">        clases3.put(<span class="string">&quot;it002&quot;</span>, <span class="string">&quot;文章&quot;</span>);</span><br><span class="line">        clases3.put(<span class="string">&quot;it003&quot;</span>, <span class="string">&quot;陈赫&quot;</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//在List集合中存储Map集合</span></span><br><span class="line">        List&lt;Map&lt;String, String&gt;&gt; grade = <span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;&gt;();</span><br><span class="line">        grade.add(clases1);</span><br><span class="line">        grade.add(clases2);</span><br><span class="line">        grade.add(clases3);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//遍历方式选择器</span></span><br><span class="line">        <span class="type">Scanner</span> <span class="variable">scanner</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Scanner</span>(System.in);</span><br><span class="line">        System.out.print(<span class="string">&quot;请输入遍历方式(1或者2):&quot;</span>);</span><br><span class="line">        <span class="type">String</span> <span class="variable">caseSelect</span> <span class="operator">=</span> scanner.nextLine();</span><br><span class="line"></span><br><span class="line">        <span class="comment">//遍历嵌套集合</span></span><br><span class="line">        <span class="keyword">for</span> (Map&lt;String, String&gt; classes : grade) &#123;</span><br><span class="line"></span><br><span class="line">            <span class="comment">//Set&lt;Map.Entry&lt;String, String&gt;&gt; set = classes.entrySet();</span></span><br><span class="line">            <span class="keyword">if</span> (caseSelect.equals(<span class="string">&quot;2&quot;</span>)) &#123;</span><br><span class="line">                <span class="comment">//遍历班级(Map遍历方式2)</span></span><br><span class="line">                <span class="keyword">for</span> (Map.Entry&lt;String, String&gt; stringStringEntry : classes.entrySet()) &#123;</span><br><span class="line">                    System.out.println(stringStringEntry.getKey() + <span class="string">&quot;: &quot;</span> + stringStringEntry.getValue());</span><br><span class="line">                &#125;</span><br><span class="line"></span><br><span class="line">                System.out.println(<span class="string">&quot;---------------&quot;</span>);</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">if</span> (caseSelect.equals(<span class="string">&quot;1&quot;</span>)) &#123;</span><br><span class="line">                <span class="comment">//使用key找value遍历(遍历方式1)</span></span><br><span class="line">                <span class="keyword">for</span> (String s : classes.keySet()) &#123;</span><br><span class="line">                    System.out.println(s + <span class="string">&quot;---&quot;</span> + classes.get(s));</span><br><span class="line">                &#125;</span><br><span class="line">                System.out.println(<span class="string">&quot;----------------&quot;</span>);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="map嵌套map">Map嵌套Map</h3>
<p>​ Map嵌套Map</p>
<div class="note primary"><ul>
<li><p>使用场景举例：一个年级有多个班级，每个班级有多名学生。要求保存每个班级的学生姓名，姓名有与之对应的学号，保存一年级所有的班级信息，班级有与之对应的班级名称。</p></li>
<li><p>思路：</p>
<ul>
<li><p>可以使用Map集合保存一个班级的学生（键是学号，值是名字）</p></li>
<li><p>可以使用Map集合保存所有班级（键是班级名称，值是班级集合信息）</p></li>
</ul></li>
<li><p>因此我们可以定义集合如下：</p>
<p>班级： <code>Map&lt;String,String&gt; 键：学号，值：姓名</code></p>
<p>举例 :
<code>Map&lt;String,String&gt; 一班 = {it001 = 迪丽热巴 , it002 = 古力娜扎,it003 = 马尔扎哈 ,it004 = 欧阳娜娜}</code></p>
<p><code>Map&lt;String,String&gt; 二班 = {it001 = 李小璐 , it002 = 白百何 ,it003 = 马蓉}</code>
<code>Map&lt;String,String&gt; 三班 = {it001 = 林丹, it002 = 文章, it003 = 陈赫}</code></p>
<p>年级：
<code>Map&lt;String , Map&lt;String,String&gt;&gt; 键：班级名称，值：具体班级信息</code></p>
<p>举例:
<code>Map&lt;String, Map&lt;String,String&gt;&gt; 年级 = {"一班" = 一班 , "二班" = 二班 , "三班" = 三班 }</code></p></li>
</ul>
</div>
<p>代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> nesting;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.HashMap;</span><br><span class="line"><span class="keyword">import</span> java.util.Map;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Author</span> EthanLiu 16693226842@163.com</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Date</span> 2024/4/23 09:26</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Project</span> JavaCode_SE_Advance</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Theme</span> Map嵌套Map</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MapNestMapDemo</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        <span class="comment">//班级1 ： 存储学号、姓名</span></span><br><span class="line">        Map&lt;String, String&gt; classes1 = <span class="keyword">new</span> <span class="title class_">HashMap</span>&lt;&gt;();</span><br><span class="line">        classes1.put(<span class="string">&quot;it001&quot;</span>, <span class="string">&quot;迪丽热巴&quot;</span>);</span><br><span class="line">        classes1.put(<span class="string">&quot;it002&quot;</span>, <span class="string">&quot;古力娜扎&quot;</span>);</span><br><span class="line">        classes1.put(<span class="string">&quot;it003&quot;</span>, <span class="string">&quot;马尔扎哈&quot;</span>);</span><br><span class="line">        classes1.put(<span class="string">&quot;it004&quot;</span>, <span class="string">&quot;欧阳娜娜&quot;</span>);</span><br><span class="line">        <span class="comment">//班级2</span></span><br><span class="line">        Map&lt;String, String&gt; classes2 = <span class="keyword">new</span> <span class="title class_">HashMap</span>&lt;&gt;();</span><br><span class="line">        classes2.put(<span class="string">&quot;it001&quot;</span>, <span class="string">&quot;李小璐&quot;</span>);</span><br><span class="line">        classes2.put(<span class="string">&quot;it002&quot;</span>, <span class="string">&quot;白百何&quot;</span>);</span><br><span class="line">        classes2.put(<span class="string">&quot;it003&quot;</span>, <span class="string">&quot;马蓉&quot;</span>);</span><br><span class="line">        <span class="comment">//班级3</span></span><br><span class="line">        Map&lt;String, String&gt; classes3 = <span class="keyword">new</span> <span class="title class_">HashMap</span>&lt;&gt;();</span><br><span class="line">        classes3.put(<span class="string">&quot;it001&quot;</span>, <span class="string">&quot;林丹&quot;</span>);</span><br><span class="line">        classes3.put(<span class="string">&quot;it002&quot;</span>, <span class="string">&quot;文章&quot;</span>);</span><br><span class="line">        classes3.put(<span class="string">&quot;it003&quot;</span>, <span class="string">&quot;陈赫&quot;</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//Map集合中存储Map集合（把班级存储到年级下 ， 给每个班级定个名字）</span></span><br><span class="line">        <span class="comment">//注意创建的写法, 多练习几次</span></span><br><span class="line">        Map&lt;String, Map&lt;String, String&gt;&gt; grade = <span class="keyword">new</span> <span class="title class_">HashMap</span>&lt;&gt;();</span><br><span class="line">        grade.put(<span class="string">&quot;一班&quot;</span>, classes1);</span><br><span class="line">        grade.put(<span class="string">&quot;二班&quot;</span>, classes2);</span><br><span class="line">        grade.put(<span class="string">&quot;三班&quot;</span>, classes3);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//遍历嵌套集合</span></span><br><span class="line">        <span class="comment">//外层遍历(遍历班级)key -&gt;&gt; value遍历</span></span><br><span class="line">        <span class="keyword">for</span> (String classnName : grade.keySet()) &#123;</span><br><span class="line">            System.out.println(classnName + <span class="string">&quot;:&quot;</span>);</span><br><span class="line">            <span class="comment">//内层遍历(遍历班级学生)</span></span><br><span class="line">            <span class="keyword">for</span> (Map.Entry&lt;String, String&gt; stu : grade.get(classnName).entrySet()) &#123;</span><br><span class="line">                System.out.println(stu.getKey() + <span class="string">&quot;---&quot;</span> + stu.getValue());</span><br><span class="line">            &#125;</span><br><span class="line">            System.out.println(<span class="string">&quot;-----------------------------&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="嵌套集合梳理">嵌套集合梳理</h3>
<ul>
<li>嵌套for循环：</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>()</span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">for</span>()</span><br><span class="line">    &#123;</span><br><span class="line">        </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li><p>可以应用于：二维数组遍历、嵌套集合遍历</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span>[][] array = &#123;  &#123;<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>&#125;,  &#123;<span class="number">4</span>,<span class="number">5</span>&#125; &#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;  i&lt;array.length;  i++)</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">//取出每一个元素（一维数组）</span></span><br><span class="line">    <span class="type">int</span>[] arr = array[i];</span><br><span class="line">    <span class="comment">//&#123;1,2,3&#125;</span></span><br><span class="line">    <span class="comment">// &#123;4,5&#125;</span></span><br><span class="line">    </span><br><span class="line">    <span class="keyword">for</span>(<span class="type">int</span> j=<span class="number">0</span>;  j&lt;arr.length  ;j++)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="type">int</span> <span class="variable">num</span> <span class="operator">=</span> arr[j];</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">list1[  list2[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>] , list3[<span class="number">4</span>,<span class="number">5</span>]  ]</span><br><span class="line">    </span><br><span class="line"><span class="comment">//遍历：list1</span></span><br><span class="line">    <span class="comment">//取出每一个元素：list2、list3</span></span><br><span class="line">    <span class="comment">//遍历 ： list2 、list3</span></span><br><span class="line">  </span><br><span class="line">Map同理</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="collections工具类">Collections工具类</h2>
<h3 id="工具类">工具类</h3>
<div class="note primary"><p>Arrays工具类：是针对数组提供了一些功能（排序、转换为字符串）</p>
<p>Collections工具类：
是针对集合提供了一些功能（排序、二分查询、乱序、添加另一个集合）</p>
</div>
<h3 id="collections工具类-1">Collections工具类</h3>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//把给定的元素添加到指定的集合中</span></span><br><span class="line">Collections.addAll( List或Set集合 ，  元素<span class="number">1</span>,元素<span class="number">2</span>,...... );</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Collections.sort( 集合 );<span class="comment">//对集合中的元素进行排序（自然排序、比较器）</span></span><br><span class="line"></span><br><span class="line">Collections.shuffle(  集合 );<span class="comment">//对集合中的元素随机打乱顺序</span></span><br></pre></td></tr></table></figure>
<h2 id="斗地主案例">斗地主案例</h2>
<h3 id="需求">需求</h3>
<div class="note primary"><p>按照斗地主的规则，完成洗牌发牌的动作。</p>
<ul>
<li><p>要求完成以下功能：</p>
<ol type="1">
<li><p>准备牌：组装54张扑克牌</p></li>
<li><p>洗牌：54张牌顺序打乱</p></li>
<li><p>发牌：三个玩家参与游戏，三人交替摸牌，每人17张牌，最后三张留作底牌。</p></li>
<li><p>看牌：查看三人各自手中的牌（按照牌的大小排序）、底牌</p></li>
</ol></li>
<li><p>规则：手中扑克牌从大到小的摆放顺序：大王,小王,2,A,K,Q,J,10,9,8,7,6,5,4,3</p></li>
</ul>
<p><img data-src="https://cdn.jsdelivr.net/gh/EthanLiu6/ImgsForMe/blog_images/image-20240423230805585.png" alt="image-20240423230805585" style="zoom:150%;"></p>
</div>
<h3 id="逻辑代码">逻辑代码</h3>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> doudizhu;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Author</span> EthanLiu 16693226842@163.com</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Date</span> 2024/4/23 20:59</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Project</span> JavaCode_SE_Advance</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Theme</span> 斗地主案例</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Test1</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        <span class="comment">//Map集合: 存储扑克牌的编号和牌面值</span></span><br><span class="line">        Map&lt;Integer, String&gt; pokerMap = <span class="keyword">new</span> <span class="title class_">HashMap</span>&lt;&gt;();</span><br><span class="line">        <span class="comment">//List集合: 存储扑克牌编号(用于洗牌等)</span></span><br><span class="line">        List&lt;Integer&gt; pokerNumber = <span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;&gt;();</span><br><span class="line">        <span class="comment">//TreeSet集合: 存储玩家信息和发牌情况(三个后面写)</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">//功能1: 准备牌</span></span><br><span class="line">        <span class="comment">//&quot;红星2&quot; &quot;黑桃2&quot; &quot;梅花2&quot; &quot;方片2&quot; ......</span></span><br><span class="line">        String[] color = &#123;<span class="string">&quot;❤&quot;</span>, <span class="string">&quot;♠&quot;</span>, <span class="string">&quot;♣&quot;</span>, <span class="string">&quot;♦&quot;</span>&#125;; <span class="comment">//颜色形状</span></span><br><span class="line">        String[] number = &#123;<span class="string">&quot;3&quot;</span>, <span class="string">&quot;4&quot;</span>, <span class="string">&quot;5&quot;</span>, <span class="string">&quot;6&quot;</span>, <span class="string">&quot;7&quot;</span>, <span class="string">&quot;8&quot;</span>, <span class="string">&quot;9&quot;</span>, <span class="string">&quot;10&quot;</span>, <span class="string">&quot;J&quot;</span>, <span class="string">&quot;Q&quot;</span>, <span class="string">&quot;K&quot;</span>, <span class="string">&quot;A&quot;</span>, <span class="string">&quot;2&quot;</span>&#125;;<span class="comment">//数值</span></span><br><span class="line"></span><br><span class="line">        <span class="type">int</span> <span class="variable">count</span> <span class="operator">=</span> <span class="number">0</span>; <span class="comment">//牌数计数(或编号)</span></span><br><span class="line">        <span class="comment">//合并牌</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">0</span>; i &lt; number.length; i++) &#123;</span><br><span class="line">            <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">j</span> <span class="operator">=</span> <span class="number">0</span>; j &lt; color.length; j++) &#123;</span><br><span class="line">                pokerMap.put(count, color[j].concat(number[i])); <span class="comment">//合并牌</span></span><br><span class="line">                pokerNumber.add(count); <span class="comment">//添加扑克牌编号</span></span><br><span class="line">                count++;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//添加大小王</span></span><br><span class="line">        <span class="keyword">if</span> (count &lt; <span class="number">55</span>) &#123;</span><br><span class="line">            pokerMap.put(count, <span class="string">&quot;小\uD83C\uDCCF&quot;</span>);</span><br><span class="line">            pokerNumber.add(count);</span><br><span class="line">            count += <span class="number">1</span>;</span><br><span class="line">            pokerMap.put(count, <span class="string">&quot;大\uD83C\uDCCF&quot;</span>);</span><br><span class="line">            pokerNumber.add(count);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//功能2: 洗牌</span></span><br><span class="line">        Collections.shuffle(pokerNumber); <span class="comment">//返回前面添加扑克牌编号</span></span><br><span class="line">        <span class="comment">//System.out.println(pokerNumber);</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">//功能3: 发牌 发的是扑克牌编号并排序</span></span><br><span class="line">        TreeSet&lt;Integer&gt; player1 = <span class="keyword">new</span> <span class="title class_">TreeSet</span>&lt;&gt;();</span><br><span class="line">        TreeSet&lt;Integer&gt; player2 = <span class="keyword">new</span> <span class="title class_">TreeSet</span>&lt;&gt;();</span><br><span class="line">        TreeSet&lt;Integer&gt; player3 = <span class="keyword">new</span> <span class="title class_">TreeSet</span>&lt;&gt;();</span><br><span class="line">        TreeSet&lt;Integer&gt; dp = <span class="keyword">new</span> <span class="title class_">TreeSet</span>&lt;&gt;(); <span class="comment">//底牌</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">idx</span> <span class="operator">=</span> <span class="number">0</span>; idx &lt; pokerNumber.size(); idx++) &#123;</span><br><span class="line">            <span class="comment">//保留底牌</span></span><br><span class="line">            <span class="keyword">if</span> (idx &gt; <span class="number">50</span>) <span class="comment">/*idx是从0开始的哦*/</span> &#123;</span><br><span class="line">                dp.add(pokerNumber.get(idx));</span><br><span class="line">                <span class="keyword">continue</span>;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">if</span> (idx % <span class="number">3</span> == <span class="number">0</span>) <span class="comment">/* 玩家1拿牌 */</span> &#123;</span><br><span class="line">                player1.add(pokerNumber.get(idx));</span><br><span class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (idx % <span class="number">3</span> == <span class="number">1</span>) <span class="comment">/* 玩家2拿牌 */</span> &#123;</span><br><span class="line">                player2.add(pokerNumber.get(idx));</span><br><span class="line">            &#125; <span class="keyword">else</span> <span class="comment">/* 玩家3拿牌 */</span> &#123;</span><br><span class="line">                player3.add(pokerNumber.get(idx));</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        System.out.println(player1.size());</span><br><span class="line">        System.out.println(player2.size());</span><br><span class="line">        System.out.println(player3.size());</span><br><span class="line">        System.out.println(dp);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//功能4: 看牌(方法定义)</span></span><br><span class="line">        lookPoker(<span class="string">&quot;Ethan&quot;</span>, player1, pokerMap);</span><br><span class="line">        lookPoker(<span class="string">&quot;Qiu&quot;</span>, player2, pokerMap);</span><br><span class="line">        lookPoker(<span class="string">&quot;BaoJie&quot;</span>, player3, pokerMap);</span><br><span class="line">        lookPoker(<span class="string">&quot;底牌&quot;</span>, dp, pokerMap);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * //功能4: 看牌(方法定义)</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> name   玩家名字</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> player 玩家牌编号</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> pokerMap 存储扑克牌的编号和牌面值</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">lookPoker</span><span class="params">(String name, TreeSet&lt;Integer&gt; player, Map&lt;Integer, String&gt; pokerMap)</span> &#123;</span><br><span class="line">        System.out.print(name + <span class="string">&quot;: &quot;</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//遍历玩家牌编号</span></span><br><span class="line">        <span class="keyword">for</span> (Integer pokerNum : player) &#123;</span><br><span class="line">            <span class="comment">//根据编号获取牌的值</span></span><br><span class="line">            System.out.print(pokerMap.get(pokerNum) + <span class="string">&quot; &quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        System.out.println();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="遇到问题">遇到问题</h3>
<p><code>TreeSet</code>集合自带自然排序的功能未掌握</p>
<figure>
<img data-src="https://cdn.jsdelivr.net/gh/EthanLiu6/ImgsForMe/blog_images/image-20240423221400608.png" alt="image-20240423221400608">
<figcaption aria-hidden="true">image-20240423221400608</figcaption>
</figure>
<h2 id="日志框架">日志框架</h2>
<h3 id="日志技术的概述">日志技术的概述</h3>
<ul>
<li>常见的日志规范：</li>
</ul>
<p><strong>Commons Logging</strong></p>
<p><strong>Simple Logging Facade for Java</strong>（slf4j）</p>
<ul>
<li><p>日志的实现框架：</p>
<p><strong>Log4J</strong></p>
<p><font color="red"><strong>Logback</strong></font>(重点学习的，其他的都大同小异)</p></li>
</ul>
<h3 id="日志技术体系结构">日志技术体系结构</h3>
<h3 id="logback概述">Logback概述</h3>
<figure>
<img data-src="https://cdn.jsdelivr.net/gh/EthanLiu6/ImgsForMe/blog_images/image-20240424002912733.png" alt="image-20240424002912733">
<figcaption aria-hidden="true">image-20240424002912733</figcaption>
</figure>
<h3 id="logback快速入门">Logback快速入门</h3>
<h4 id="补充">补充</h4>
<p>使用java语言开发完成的程序，要给其他人使用，怎么办呢？</p>
<ul>
<li>把程序打包： xxxx.jar （jar文件是java文件压缩包）</li>
</ul>
<p>要使用第三方开发好的程序，怎么办？</p>
<ul>
<li>在自己的项目工程下，导入xxx.jar包</li>
</ul>
<h4 id="使用logback的步骤">使用Logback的步骤：</h4>
<ol type="1">
<li>导入Logback所需的相关jar文件，并添加到项目资源库中
<ul>
<li>在项目工程下新建<code>lib</code>文件夹，把logback需要的jar文件存放到该文件夹下</li>
<li>lib目录下的存储的jar文件，添加到当前项目资源库中</li>
</ul></li>
<li>把logback核心配置文件，拷贝到当前项目的src目录下</li>
<li>在类中获取到Logger日志对象，使用日志对象中的API方法记录需要的操作信息</li>
</ol>
<h4 id="logback日志框架的核心logback.xml">Logback日志框架的核心：logback.xml</h4>
<ul>
<li>xml文件</li>
</ul>
<p>Logback配置详解-输出位置、格式设置</p>
<p>Logback配置详解-日志级别设置</p>
<p>（略）</p>
<h4 id="logback日志级别从大到小">Logback日志级别（从大到小）：</h4>
<ol type="1">
<li>error //错误</li>
<li>warn //警告</li>
<li>info //信息</li>
<li>debug //调试</li>
<li>trace //追踪（例：追踪用户行为轨迹）</li>
</ol>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="reward-container">
  <div>请我一杯咖啡吧！</div>
  <button>
    赞赏
  </button>
  <div class="post-reward">
      <div>
        <img src="/images/wChat.png" alt="Ethan Liu 微信">
        <span>微信</span>
      </div>

  </div>
</div>

          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>Ethan Liu
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="http://ethanliu6.github.io/2024/04/22/JavaNotes/JavaSE%E8%BF%9B%E9%98%B6/day07/2024-04-19-JavaSE%E8%BF%9B%E9%98%B6%E2%80%94%E2%80%94Day06-%E6%8E%92%E5%BA%8F%E6%9F%A5%E6%89%BE%E7%AE%97%E6%B3%95%E3%80%81Map%E9%9B%86%E5%90%88%E3%80%81%E9%9B%86%E5%90%88%E5%B5%8C%E5%A5%97%E3%80%81%E6%96%97%E5%9C%B0%E4%B8%BB%E6%A1%88%E4%BE%8B/" title="JavaSE进阶——Day07 集合嵌套、Collections工具类、日志框架">http://ethanliu6.github.io/2024/04/22/JavaNotes/JavaSE进阶/day07/2024-04-19-JavaSE进阶——Day06-排序查找算法、Map集合、集合嵌套、斗地主案例/</a>
  </li>
  <li class="post-copyright-license">
      <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLXNhLzQuMC8="><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


          <div class="post-tags">
              <a href="/tags/Java/" rel="tag"><i class="fa fa-tag"></i> Java</a>
              <a href="/tags/Java%E8%BF%9B%E9%98%B6/" rel="tag"><i class="fa fa-tag"></i> Java进阶</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2024/04/22/love/%E4%B8%AA%E4%BA%BA%E6%97%A5%E8%AE%B024-04-22/" rel="prev" title="个人日记24-04-22">
                  <i class="fa fa-angle-left"></i> 个人日记24-04-22
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2024/04/25/JavaNotes/JavaSE%E8%BF%9B%E9%98%B6/day08/JavaSE%E8%BF%9B%E9%98%B6%E2%80%94%E2%80%94Day08-%E5%BC%82%E5%B8%B8,Lambda%E8%A1%A8%E8%BE%BE%E5%BC%8F,Stream%E6%B5%81%20/" rel="next" title="JavaSE进阶——Day08 异常、Lambda表达式、Stream流、File类、递归">
                  JavaSE进阶——Day08 异常、Lambda表达式、Stream流、File类、递归 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






    <div class="comments" id="SOHUCS" sid="37a2fead96ff8c04b3a8e68e23131f04"></div>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2023-2024 – 
    <span itemprop="copyrightYear">2024</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">Is Ethan's</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
    <span title="站点总字数">113k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">6:51</span>
  </span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>

    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

  <span class="exturl github-corner" data-url="aHR0cHM6Ly9naXRodWIuY29tL0V0aGFuTGl1Ni8=" title="在 GitHub 上关注我" aria-label="在 GitHub 上关注我"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></span>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.33/fancybox/fancybox.umd.js" integrity="sha256-+2+qOqR8CKoHh/AsVR9k2qaDBKWjYNC2nozhYmv5j9k=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/medium-zoom/1.1.0/medium-zoom.min.js" integrity="sha256-ZgMyDAIYDYGxbcpJcfUnYwNevG/xi9OHKaR/8GK+jWc=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/bookmark.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>

  <script class="next-config" data-name="pdf" type="application/json">{"object_url":{"url":"https://cdnjs.cloudflare.com/ajax/libs/pdfobject/2.2.12/pdfobject.min.js","integrity":"sha256-g2xji1rlE3KsGVClvuxTbcR0Kn2+wtQADSff2Tbb4zA="},"url":"/lib/pdf/web/viewer.html"}</script>
  <script src="/js/third-party/tags/pdf.js"></script>



  <script src="/js/third-party/fancybox.js"></script>



  
  <script data-pjax async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"all","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


  <script src="https://cdnjs.cloudflare.com/ajax/libs/quicklink/2.3.0/quicklink.umd.js" integrity="sha256-yvJQOINiH9fWemHn0vCA5lsHWJaHs6/ZmO+1Ft04SvM=" crossorigin="anonymous"></script>
  <script class="next-config" data-name="quicklink" type="application/json">{"enable":true,"home":true,"archive":true,"delay":true,"timeout":3000,"priority":true,"url":"http://ethanliu6.github.io/2024/04/22/JavaNotes/JavaSE%E8%BF%9B%E9%98%B6/day07/2024-04-19-JavaSE%E8%BF%9B%E9%98%B6%E2%80%94%E2%80%94Day06-%E6%8E%92%E5%BA%8F%E6%9F%A5%E6%89%BE%E7%AE%97%E6%B3%95%E3%80%81Map%E9%9B%86%E5%90%88%E3%80%81%E9%9B%86%E5%90%88%E5%B5%8C%E5%A5%97%E3%80%81%E6%96%97%E5%9C%B0%E4%B8%BB%E6%A1%88%E4%BE%8B/"}</script>
  <script src="/js/third-party/quicklink.js"></script>
<script class="next-config" data-name="changyan" type="application/json">{"enable":true,"appid":"cyxf6tytI","appkey":"90987f30c4b5248baad5a04c7a6abfe1","count":true}</script>
<script src="/js/third-party/comments/changyan.js"></script>

</body>
</html>
